﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using AcctrueWMS.Foundation.Render;
using AcctrueWMS.Foundation.Web;
namespace AcctrueWMS.Foundation.Data
{
    public interface IDataModelContext
    {
        void FillModel(DataModel model);
        DataModel Select(DataModel model, string condition);
        DataModel Select(DataModel model, string condition, string orderBy);
        DataModel Select(DataModel model, string condition, int startIndex, int endIndex);
        DataModel Select(DataModel model, string condition, string orderBy, int startIndex, int endIndex);

        DataModel Range(DataModel model, string condition, int start, int end);
        DataModel Order(DataModel model, string orderBy);
        DataModel Single(DataModel model, string condition);
        string  Save(DataModel model, string state);  
        int Delete(DataModel model, string condition);
        DataModel Join(DataModel left, DataModel right, string condition);
        DataModelCell GetCell(DataModel model, int row, int col);
        DataModelCell GetCell(DataModel model, int row, string colName);
        void SetCell(DataModel model, int row, int col, object value);
        void SetCell(DataModel model, int row, string colName, object value);
        string RenderColumn(DataModelColumn column);
        int GetSequenceNo(string tableName, string colTag);
        /// <summary>
        /// 为列产生系统号
        /// </summary>
        /// <returns></returns>
        string GetSequenceNo(DataModelColumn column);

        string RenderKeyValue(DataModel model);
        /// <summary>
        /// 分析字符串，字符串格式与DataModel列定义值类似，形如：displayType=tree;data=wmsql(sth);
        /// </summary>
        /// <param name="expr"></param>
        /// <returns></returns>
        string CreateControl(string expr);

        /// <summary>
        /// 根据含数据获取命令和VTL语法的表达式来返回值
        /// </summary>
        /// <param name="expr"></param>
        /// <returns></returns>
        object Evaluate(string expr);
        /// <summary>
        /// 根据expr生成控件
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="expr"></param>
        /// <returns></returns>
        string RenderCell(DataModelCell cell, string expr);
        string RenderCell(DataModelCell cell);
        /*
        Dictionary<string, Type> FilldirType(Dictionary<string, Type> dirType);
         * */
        /// <summary>
        /// 别名管理器
        /// </summary>
        IClsAliasManager AliasManager
        {
            get;
            set;
        }

        string ApplicationPath
        {
            get;
            set;
        }

        string FilePath
        {
            get;
            set;
        }
        /// <summary>
        /// 通用的WebService地址
        /// </summary>
        string CommmonServiceUrl
        {
            get;
            set;
        }
        IModelRender Render
        {
            get;
        }

        string RenderAsQuery(DataModelColumn dataModelColumn);
        string RenderAsQuery(DataModelColumn column, string expr);
        int RenderMode
        {
            get;
        
        }
        /// <summary>
        /// 当前登录用户
        /// </summary>
        SystemUser CurrentUser
        {
            get;
        }
        DataModel CurrentModel
        {
            get;
        }
        /// <summary>
        /// 当前URL
        /// </summary>
        string CurrentUrl
        {
            get;
        }
        DateTime GetDate();

        /// <summary>
        /// 根据页面的表单信息，得到相应的数据库查询串
        /// </summary>
        /// <param name="modelName">模型名称</param>
        /// <param name="expr">表单信息，形如：address=sdfdf&name=sdfdf</param>
        /// <param name="isPrimary">是否模糊匹配</param>
        /// <returns></returns>
        string GetQueryCondition(string modelName, string expr, bool isApprox);
        /// <summary>
        /// 得到单元格的值
        /// </summary>
        /// <param name="cell">单元格</param>
        /// <param name="row">如果不为空，则使用row的数据来填充</param>
        object GetCellValue(DataModelCell cell, DataRow row);

       
    }
}
